package com.hsyt.pfc.core.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Description: 线程池自动配置
 * @ClassName: ThreadPoolAutoConfiguration
 * @Package: com.hsyt.pfc.core
 * @Author: wangze@hsyuntai.com
 * @Date: 2018年9月10日 9:15
 * @Copyright: 版权归 HSYUNTAI 所有
 */
@Configuration
public class ThreadPoolAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(ThreadPoolTaskExecutor.class)
    @ConfigurationProperties("spring.threadPool")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;
    }
}
